using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using DataSecurity.StandartInterfaces;

namespace DataSecurity
{
    /// <summary>
    /// This class shields the client from the details of database specific 
    /// data-access objects. It returns the appropriate data-access objects 
    /// according to the configuration in web.config.
    /// </summary>
    /// <remarks>
    /// GoF Design Patterns: Factory, Singleton, Proxy.
    /// 
    /// This class makes extensive use of the Factory pattern in determining which 
    /// database specific DAOs (Data Access Objects) to return.
    /// 
    /// This class is like a Singleton -- it is a static class (Shared in VB) and 
    /// therefore only one 'instance' will ever exist.
    /// 
    /// This class is a Proxy as it 'stands in' for the actual Data Access Object Factory.
    /// </remarks>
    public static class DataAccess
    {
        // The static field initializers below are thread safe.
        // Furthermore, they are executed in the order in which they appear
        // in the class declaration. Note: if a static constructor
        // is present you want to initialize these in that constructor.
        private static readonly string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
        private static readonly IDaoFactory factory = DaoFactories.GetFactory(connectionStringName);

        /// <summary>
        /// Gets the site DAO.
        /// </summary>
        /// <value>
        /// The site DAO.
        /// </value>
        public static ISite SiteDao { get { return factory.Site; } }

        /// <summary>
        /// Gets the permission DAO.
        /// </summary>
        /// <value>
        /// The permission DAO.
        /// </value>
        public static IPermission PermissionDao { get { return factory.Permission; } }

        /// <summary>
        /// Gets the role DAO.
        /// </summary>
        /// <value>
        /// The role DAO.
        /// </value>
        public static IRole RoleDao { get { return factory.Role; } }

        /// <summary>
        /// Gets the role in site DAO.
        /// </summary>
        /// <value>
        /// The role in site DAO.
        /// </value>
        public static IRoleInSite RoleInSiteDao { get { return factory.RoleInSite; } }

        /// <summary>
        /// Gets the permission in site DAO.
        /// </summary>
        /// <value>
        /// The permission in site DAO.
        /// </value>
        public static IPermissionInSite PermissionInSiteDao { get { return factory.PermissionInSite; } }

        /// <summary>
        /// Gets the user DAO.
        /// </summary>
        /// <value>
        /// The user DAO.
        /// </value>
        public static IUser UserDao { get { return factory.User; } }
    }
}
